home *** CD-ROM | disk | FTP | other *** search
- unit MemSizeU;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ExtCtrls, StdCtrls;
-
- type
- TForm1 = class(TForm)
- Button1: TButton;
- Panel1: TPanel;
- Timer1: TTimer;
- Label1: TLabel;
- procedure Button1Click(Sender: TObject);
- procedure Timer1Timer(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- uses
- PSAPI;
-
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- with TEdit.Create(Self) do
- begin
- Parent := Panel1;
- Left := Random(Panel1.Width - Width - 1);
- Top := Random(Panel1.Height - Height - 1);
- end;
- end;
-
- procedure TForm1.Timer1Timer(Sender: TObject);
- var
- SI: TSystemInfo;
- PageSize: DWord;
- CurrentProcessHandle: THandle;
- DWords: array[0..2048] of DWord;
- Res: DWord;
- const
- KiloByte = 1024;
- begin
- GetSystemInfo(SI);
- PageSize := SI.dwPageSize div KiloByte;
- CurrentProcessHandle := OpenProcess(
- PROCESS_QUERY_INFORMATION, False, GetCurrentProcessId);
- //Working set only valid on NT
- if Win32Platform = VER_PLATFORM_WIN32_NT then
- if QueryWorkingSet(CurrentProcessHandle, @DWords, SizeOf(DWords)) then
- Label1.Caption :=
- Format('Working set = %d kb', [DWords[0] * PageSize])
- else
- begin
- //If QueryWorkingSet fails, show error no./msg.
- Res := GetLastError;
- Label1.Caption :=
- Format('Cannot calculate working set, Win32 error %d (%s)',
- [Res, SysErrorMessage(Res)])
- end
- else
- Label1.Caption := 'Working set only valid on NT platforms'
- end;
-
- end.
-